package com.ams.protocol.rtmp;

import java.io.IOException;
import com.ams.io.BufferList;
import com.ams.io.BufferInputStream;

class RtmpChunkDataReader {
    private RtmpHeader header;
    private BufferList chunkData = new BufferList();
    private int chunkSize;

    public RtmpChunkDataReader(RtmpHeader header) {
        this.header = header;
        this.chunkSize = header.getSize();
    }

    public void read(BufferInputStream in, int size) throws IOException {
        if (size <= 0)
            return;
        chunkData.write(in.readByteBuffer(size));
        chunkSize -= size;
    }

    public BufferList getChunkData() {
        return chunkData;
    }

    public int getChunkSize() {
        return chunkSize;
    }

    public RtmpHeader getHeader() {
        return header;
    }
}
